<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vue指令</title>
    <style>
      p {
        font-size: 20px;
      }
      .box {
        border: 5px solid black;
        height: 150px;
        width: 250px;
        padding: 20px 10px;
        text-align: center;
      }
      .img {
        width: 150px;
        height: 250px;
      }
      img {
        width: 100%;
        height: 100%;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <p v-if="gender===1">男：帅哥</p>
      <p v-else>女：美女</p>
      <hr />
      <p v-if="score>=90">成绩为A等，奖励手机一部</p>
      <p v-else-if="score>=70">成绩为B等，奖励音乐会门票一张</p>
      <p v-else-if="score>=60">成绩为B等，奖励精美贴纸一张</p>
      <p v-else>成绩为D等，罚款二十</p>
      <button @click="count--">-</button>
      <span>{{count}}</span>
      <button @click="count++">+</button>
      <br /><br />
      <div class="box">
        <p>远强自动售货机</p>
        <button @click="buy(5)">橙汁5元</button>
        <button @click="buy(6)">牛奶6元</button>
        <p>余额：{{money}}</p>
      </div>
      <br /><br />
      <button v-show="index>0" @click="index--">上一张</button>
      <div class="img">
        <img :src="list[index]" alt="" />
      </div>
      <button v-show="index<(list.length-1)" @click="index++">下一张</button>
      <br /><br />
      <ul>
        <h2>远强爱看的国漫</h2>
        <li v-for="(item,index) in list2">{{item}}</li>
      </ul>
      <br /><br />
      <ul>
        <h2>远强图书</h2>
        <li v-for="(item,index) in list3" :key="item.id">
          <span>{{item.name}}</span>
          <span>{{item.author}}</span>
          <button @click="del(item.id)">删除</button>
        </li>
      </ul>
      <br /><br />
      <div>
        账户<input type="text" v-model="username" /><br /><br />
        密码<input type="text" v-model="password" /><br /><br />
        <button @click="login">登录</button>
        <button @click="reset">重置</button>
      </div>
      <br /><br />
      <button @click="fn">切换</button>
      <p v-show="isShow">伟大的中国人民万岁</p>
    </div>
    <script src="../vue.js"></script>
    <script>
      const app = new Vue({
        el: "#app",
        data: {
          username: "",
          password: "",
          index: 0,
          gender: 2,
          score: 70,
          count: 100,
          isShow: true,
          money: 20,
          list: [
            "./图片/七影01.jpg",
            "./图片/七影02.jpg",
            "./图片/七影03.jpg",
            "./图片/七影04.jpg",
          ],
          list2: ["画江湖之不良人", "刺客五六七", "秦时明月", "天行九歌"],
          list3: [
            { id: 1, name: "<<斗罗大陆>>", author: "唐家三少" },
            { id: 2, name: "<<斗破苍穹>>", author: "天蚕土豆" },
            { id: 3, name: "<<完美世界>>", author: "辰东" },
            { id: 4, name: "<<妖神记>>", author: "发飙的蜗牛" },
          ],
        },
        methods: {
          fn() {
            this.isShow = !this.isShow;
          },
          buy(price) {
            if (this.money >= price) {
              this.money -= price;
            } else {
              alert("余额已经严重不足，该充钱了，穷鬼");
            }
          },
          del(id) {
            this.list3 = this.list3.filter((item) => item.id !== id);
          },
          login() {
            console.log(this.username);
            console.log(this.password);
          },
          reset() {
            this.username = "";
            this.password = "";
          },
        },
      });
    </script>
  </body>
</html>
